package com.cloudcc.mobile.weight.viewgroup;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.cloudcc.mobile.R;

/** 
 * @deprecated 王志强
* @Description: TODO() 
* @author wangzhiqiang
* @date 2015-10-26 下午5:32:38 
*  
*/
public class CheckImage extends FrameLayout implements OnClickListener {

	/**
	 * 底片显示的imageview
	 */
	private ImageView mDisplayImageView;
	/**
	 * 覆盖效果的iamgeview
	 */
	private ImageView mOverImageView;
	private CheckBox mCheckBox;
	private OnCheckedChangeListener mOnCheckedChangeListener;
	private boolean isChecked = false;
	private boolean isFrist =true;

	public CheckImage(Context context) {
		this(context, null);
	}

	public CheckImage(Context context, AttributeSet attrs) {
		this(context, attrs,0);
	}

	public CheckImage(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

		LayoutInflater.from(getContext()).inflate(
				R.layout.widget_checked_image, this);

		mDisplayImageView = (ImageView) findViewById(R.id.iv1);
		mOverImageView = (ImageView) findViewById(R.id.iv2);
		mCheckBox = (CheckBox) findViewById(R.id.cb1);
		
		setOnClickListener(this);
	}
	
	public void setChecked(){
		setChecked(!isChecked);
	}

	/**
	 * 设置选中
	 * @param checked
	 */
	public void setChecked(boolean checked) {
		
		if (isChecked!=checked) {
			isChecked =checked;
			mOverImageView.setVisibility(checked ? View.VISIBLE : View.GONE);

			mCheckBox.setChecked(checked);
			
			if (mOnCheckedChangeListener!=null) {
				mOnCheckedChangeListener.onCheckedChanged(null, checked);
				
			}
		}
		



	}

	public boolean isChecked() {
		return isChecked;
	}
	
	public void setOnCheckedChangeListener(OnCheckedChangeListener l){
		this.mOnCheckedChangeListener =l;
	}
	/**
	 * 获得iamgeview
	 * 
	 * @return
	 */
	public ImageView getImageView() {
		return mDisplayImageView;
	}

	@Override
	public void onClick(View arg0) {
		setChecked();
	}

}
